package vesion2.barrier;

import vesion2.object.GameObject;
import vesion2.object.Point;
import vesion2.tank.Bullet;
import vesion2.tank.EnemyTank;
import vesion2.tank.MyTank;

import java.awt.*;

public class ProtectLimit extends Barrier{
    int ProtectTank;

    /**
     *
     * @param left_up
     * @param width
     * @param height
     * @param protectTank 0-自己,1-敌人
     */
    public ProtectLimit(Point left_up, int width, int height,int protectTank) {
        super(left_up, width, height);
        if(protectTank==0)
        backColor=new Color(0xE78BF0);
        else
            backColor=new Color(0x15F1F1);
        this.ProtectTank=protectTank;
    }
    public ProtectLimit(){
        this(new Point(),0,0,0);
    }

    public int getProtectTank() {
        return ProtectTank;
    }

    public void setProtectTank(int protectTank) {
        ProtectTank = protectTank;
    }

    @Override
    public boolean isIntersect(GameObject object) { ;
        if(object instanceof EnemyTank) {
            if (super.isIntersect(object) && ProtectTank == 0)
                return true;
        }
        if(object instanceof MyTank)
            if(super.isIntersect(object)&&ProtectTank==1)
                return true;

        if(object instanceof Bullet)
            if(super.isIntersect(object))
                return true;

        return false;
    }

    @Override
    public void collideWithObject(GameObject object) {
        if(object instanceof Bullet)
            ((Bullet)object).setAlive(false);
    }

    @Override
    public void draw(Graphics g) {
        g.setColor(backColor);
        g.fill3DRect(left_up.getX(),left_up.getY(),getWidth(),getHeight(),false);
    }
}
